//package com.digiwin.demo.influx;
//
//import com.influxdb.client.InfluxDBClient;
//import com.influxdb.client.InfluxDBClientFactory;
//import com.influxdb.client.QueryApi;
//import com.influxdb.client.WriteApi;
//import com.influxdb.client.domain.WritePrecision;
//import com.influxdb.client.write.Point;
//import com.influxdb.query.FluxRecord;
//import com.influxdb.query.FluxTable;
//
//import java.time.Instant;
//import java.util.List;
//import java.util.concurrent.ThreadLocalRandom;
//import java.util.concurrent.TimeUnit;
//
///**
// * @Author yanggld
// * @Date 2020/1/2-17:32
// * @Description
// */
//public class Test {
//
//	static String token1 = "7OAfDlRiyGnHOdV9rcSvog78WJilHM1geAw_Z4m9xrVuVl1Nov6HfnZpj1LJUmN8S9k9ej5cY_7dDuAmlYKB3Q==";
//	private static char[] token = token1.toCharArray();
//
//
//	public static void main(String[] args) throws InterruptedException {
//		InfluxDBClient influxDBClient = InfluxDBClientFactory.create("http://172.16.1.198:9999", token);
//
//		try (WriteApi writeApi = influxDBClient.getWriteApi()) {
//			int i = 0;
//			while (i < 1000) {
//				i ++;
//				//
//				// Write by Data Point
//				//
//				double random = ThreadLocalRandom.current().nextDouble(10);
//				Point point = Point.measurement("temperature")
//						.addTag("location", "west")
//						.addField("value", random)
//						.time(Instant.now().getEpochSecond()  , WritePrecision.S);
//
//				writeApi.writePoint("mytest", "digiwin", point);
//				Thread.sleep(1000);
//				//
//				// Write by LineProtocol
//				//
////			writeApi.writeRecord("mytest", "digiwin", WritePrecision.NS, "temperature,location=north value=160.0");
//			}
//		}
//
//
//		String flux = "from(bucket:\"mytest\") |> range(start: 0)";
//
//		QueryApi queryApi = influxDBClient.getQueryApi();
//
//		List<FluxTable> tables = queryApi.query(flux, "digiwin");
//		for (FluxTable fluxTable : tables) {
//			List<FluxRecord> records = fluxTable.getRecords();
//			for (FluxRecord fluxRecord : records) {
//				System.out.println(fluxRecord.getTime() + ": " + fluxRecord.getValueByKey("_value"));
//			}
//		}
//
//		influxDBClient.close();
//
//	}
//}
